<!--
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
-->
<!--
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
-->
<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%"
      row-key="objectId"
      :tree-props="{ children: 'list' }"
    >
      <el-table-column label="分类层级">
        <template #default="scope">
          {{ scope.row.parent == "0-0" ? "一级类目" : "" }}
        </template>
      </el-table-column>
      <el-table-column prop="name" label="分类名称" />
      <el-table-column label="上架状态">
        <template #default="scope">
          <el-switch v-model="scope.row.online" />
        </template>
      </el-table-column>
      <el-table-column label="分类图标">
        <template #default="scope">
          <img :src="scope.row.icon" alt="" style="height: 40px" />
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button type="primary" @click="handleEdit(scope.row)"
            >编辑</el-button
          >
          <el-button type="danger">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { classifyGet } from "@/api/job";
export default {
  data() {
    return {
      tableData: [],
    };
  },
  created() {
    classifyGet(true).then((res) => {
      // this.tableData = res.data.results;
      let { results } = res.data;
      let parentArr = results.filter((item) => item.parent == "0-0");
      parentArr.forEach((item) => {
        item.list = results.filter((child) => child.parent == item.objectId);
      });
      console.log(parentArr);
      this.tableData = [...parentArr];
    });
  },
  methods: {
    handleEdit(row) {
      this.$router.push({
        path: "/classify/edit",
        query: {
          ...row,
          online1: row.online,
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
